package com.neusoft.crm.service.impl;

import com.neusoft.crm.mapper.ClientReprieveLoseMapper;
import com.neusoft.crm.po.ClientInfo;
import com.neusoft.crm.po.ClientReprieveLose;
import com.neusoft.crm.service.IClientReprieveLoseService;
import com.neusoft.crm.utils.Slf4j2Logger;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 暂缓流失客户信息接口实现类
 *
 * @author lanan1207
 */
@Service
public class ClientReprieveLoseServiceImpl implements IClientReprieveLoseService {
    @Autowired
    ClientReprieveLoseMapper lostClientMapper;

    @Override
    public List<ClientInfo> selectDeferredLossCustomerList(ClientInfo clientInfo) {
        return lostClientMapper.selectDeferredLossCustomerList(clientInfo);
    }

    @Override
    public int updateDeferredLossItemList(List<ClientReprieveLose> clientReprieveLose) {
        int influenceLineCount = 0;
        try {
            influenceLineCount = lostClientMapper.updateDeferredLossItemList(clientReprieveLose);
        } catch (PersistenceException e) {
            Slf4j2Logger.LOGGER.error("暂缓流失措施更新失败，失败原因为：", e);
        }
        return influenceLineCount;
    }

    @Override
    public List<ClientInfo> selectLostCustomerDetails(ClientInfo clientInfo) {
        return lostClientMapper.selectLostCustomerDetails(clientInfo);
    }

    @Override
    @CacheEvict(value = "ClientInfoList", allEntries = true)
    public int confirmLostClient(ClientInfo clientInfo) {
        int influenceLineCount = 0;
        try {
            influenceLineCount = lostClientMapper.confirmLostClient(clientInfo);
        } catch (PersistenceException e) {
            Slf4j2Logger.LOGGER.error("客户确认流失失败，失败原因为：", e);
        }
        return influenceLineCount;
    }

    @Override
    @CacheEvict(value = "ClientInfoList", allEntries = true)
    public int regainLostClient(ClientInfo clientInfo) {
        int influenceLineCount = 0;
        try {
            influenceLineCount = lostClientMapper.regainLostClient(clientInfo);
        } catch (PersistenceException e) {
            Slf4j2Logger.LOGGER.error("客户挽救失败，失败原因为：", e);
        }
        return influenceLineCount;
    }

    @Override
    public List<ClientInfo> selectLostClient(ClientInfo clientInfo) {
        return lostClientMapper.selectLostClient(clientInfo);
    }

    @Override
    public List<ClientReprieveLose> selectDeferredLossItemById(ClientInfo clientInfo) {
        return lostClientMapper.selectDeferredLossItemById(clientInfo);
    }

    @Override
    public int insertDeferredLossItem(ClientReprieveLose clientReprieveLose) {
        int influenceLineCount = 0;
        try {
            influenceLineCount = lostClientMapper.insertDeferredLossItem(clientReprieveLose);
        } catch (PersistenceException e) {
            Slf4j2Logger.LOGGER.error("客户暂缓流失措施新增失败，失败原因为：", e);
        }
        return influenceLineCount;
    }

}
